<?
	function GetConnection()
	{
		return new mysqli('wyvern.cs.newpaltz.edu', 'N02036842', 's741780', 'N02036842_db');
	}
	//************************************************
	function GetDataBase()
	{
		$conn = GetConnection();
		$results = $conn->query("SELECT * FROM Inventory");
		$conn->close();
		$rs = $results->fetch_assoc();
		return $rs;		
	}
	//************************************************
	function UpdateItem($rs)
	{
		$conn4 = GetConnection();
		if($rs['ItemName'] == null){
			$name = $conn4->query("SELECT ItemName FROM Inventory WHERE ItemId='$rs[ItemId]'");
			$rs['ItemName'] = $name;
		}
		$conn4->close();
		$conn3 = GetConnection();
		$update = "UPDATE Inventory SET updated_at=NOW(), ItemName='$rs[ItemName]', UnitLeft=UnitLeft+'$rs[UnitTotal]', UnitTotal = UnitLeft, Price='$rs[Price]' WHERE ItemId='$rs[ItemId]'";
		$conn3->query($update);
		$error = $conn3->error;	
		$conn3->close();
	}
	//************************************************
	function AddItem($rs)
	{
		$conn2 = GetConnection();
		$sql = "INSERT INTO Inventory (id, created_at, ItemName, ItemId, UnitTotal, UnitLeft, Price) VALUES ('NULL', NOW(), '$rs[ItemName]', '$rs[ItemId]', '$rs[Quantity]', '$rs[Quantity]', '$rs[Price]')";
		$conn2->query($sql);
		$conn2->close();
	}
	//************************************************
	function DeleteItem($rs)
	{
		echo(" In Delete function");
		$conn1 = GetConnection();
		echo(" Got $conn");
		$sql = "DELETE FROM Inventory WHERE ItemId='$rs[ItemId]'";
		echo(" Made $sql");
		$conn1->query($sql);
		echo(" Query");
		$conn1->close();
	}